package com.ruoyi.sumfun.blog.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.sumfun.blog.service.TagService;
import com.ruoyi.system.api.domain.blog.Tag;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 标签Controller
 *;'
 * @author sumfun
 * @date 2024-04-21
 */
@Api(value = "标签信息Controller" , tags = {"标签信息" })
@RestController
@RequestMapping("/tag")
public class TagController extends BaseController {
    @Autowired
    private TagService tagService;

    /**
     * 查询标签信息列表
     */
//@RequiresPermissions("system:info:list")
    @ApiOperation("查询标签信息列表")
    @GetMapping("/list")
    public TableDataInfo list(Tag tag) {
        startPage();
        List<Tag> list = tagService.selectList(tag);
        return getDataTable(list);
    }

    @ApiOperation("查询标签信息不分页列表")
    @GetMapping("/v2/list")
    public AjaxResult v2list(Tag tag) {
        List<Tag> list = tagService.selectList(tag);
        return success(list);
    }


    /**
     * 查询标签信息列表
     */
//@RequiresPermissions("system:info:list")
    @ApiOperation("数据中心查询标签信息列表")
    @GetMapping("/getDataList")

    public R getDataList(Tag tag) {

        List<Tag> list = tagService.selectList(tag);
        R result = new R();
        result.setCode(200);
        result.setMsg("查询成功");
        result.setData(list);
        return result;
    }


    /**
     * 导出标签信息列表
     */
    //@RequiresPermissions("system:info:export")
    @ApiOperation("导出标签信息列表")
    @Log(title = "标签信息" , businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Tag tag) {
        List<Tag> list = tagService.selectList(tag);
        ExcelUtil<Tag> util = new ExcelUtil<Tag>(Tag. class);
        util.exportExcel(response, list, "标签信息数据");
    }

    /**
     * 获取标签信息详细信息
     */
    //@RequiresPermissions("system:info:query")
    @ApiOperation("获取标签信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(tagService.selectById(id));
    }

    /**
     * 新增标签信息
     */
    @ApiOperation("新增标签信息")
    @Log(title = "新增标签信息" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Tag tag) {
        return toAjax(tagService.insert(tag));
    }

    /**
     * 修改标签信息
     */
    //@RequiresPermissions("system:info:edit")
    @ApiOperation("修改标签信息")
    @Log(title = "标签信息" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Tag tag) {
        return toAjax(tagService.update(tag));
    }

    /**
     * 删除标签信息
     */
    //@RequiresPermissions("system:info:remove")
    @ApiOperation("删除标签信息")
    @Log(title = "标签信息" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(tagService.deleteByIds(ids));
    }
}
